package com.goldgov.utils;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;

public class SeleniumProccessor implements PageProcessor {
    private Site site = Site.me().setRetryTimes(3).setSleepTime(1000).setTimeOut(3000)
            .setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36");
 
    @Override
    public void process(Page page) {
//    	new ChromeDriver("C:\\Users\\Administrator.EDZ-20180521SLP\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe");
//    	System.setProperty("webdriver.firefox.marionette","C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");
    	System.setProperty("webdriver.chrome.driver", "C:\\\\Users\\\\Administrator.EDZ-20180521SLP\\\\AppData\\\\Local\\\\Google\\\\Chrome\\\\Application\\\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
//        driver.get("http://47.93.232.214/page/portal/alogin/login.html");
        driver.get("https://www.baidu.com/");
        driver.quit();
        //防止页面未能及时加载出来而设置一段时间延迟
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        //找到登录按钮，点击
////        driver.findElement(By.id("submitBtn")).click();
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
////        driver.findElement(By.id("dialogLWrap")).findElement(By.id("dialogLPlatform")).findElement(By.tagName("a")).click();
//        driver.findElement(By.id("username")).sendKeys("admin");
//        driver.findElement(By.id("password")).sendKeys("nxdyAdmin");
//        driver.findElement(By.xpath("//p[@class='oauth_formbtn']/a[@node-type='submit']")).click();
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        driver.findElement(By.id("submitBtn")).click();
//        driver.findElement(By.xpath("//p[@class='oauth_formbtn']/a[@node-type='submit']")).click();
 
    }
 
    @Override
    public Site getSite() {
        return site;
    }
 
//    public static void main(String[] args) {
//        List<SpiderListener> spiderListeners = new ArrayList<>();
//        SpiderListener spiderListener = new SpiderListener() {
//            @Override
//            public void onSuccess(Request request) {
//                System.out.println("sucsess");
//            }
// 
//            @Override
//            public void onError(Request request) {
// 
//            }
//        };
//        spiderListeners.add(spiderListener);
//        Spider.create(new SeleniumProccessor())
//                .setSpiderListeners(spiderListeners)
//                .addUrl("http://47.93.232.214")
//                .thread(5)
//                .start();
//    }
}